package cn.bdqn.pn.realm;

/*import com.shiro.entity.User;
import com.shiro.service.UserService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;*/

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import javax.annotation.Resource;

public class UserRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        return null;
    }

   /* @Resource
    private UserService userService;

    *//**
     * 为当前登录的用户授权
     * @param principal
     * @return
     *//*
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
       //获取当前登录用户信息
        String username=(String)principal.getPrimaryPrincipal();
        //创建授权，验证对象
        SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();

        try {
            //授予角色
            authorizationInfo.setRoles(userService.getRoles(username));
            //授予权限
            authorizationInfo.setStringPermissions(userService.getPermissions(username));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return authorizationInfo;
    }

    *//**
     * 为当前登录用户进行身份验证
     * @param token
     * @return
     * @throws AuthenticationException
     *//*
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //获取用户名
        String username = (String)token.getPrincipal();
        //调用根据用户名查询用户信息的方法
        User user = userService.getUserByName(username);
        if(user!=null){
            //进行身份验证
            AuthenticationInfo authenticationInfo=new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),"ha");
            return authenticationInfo;
        }
        //返回null，表示验证失败
        return null;
    }*/
}
